<?php
/**
 * @file:      compositio/template.php
 * @author:    Kitt Hodsden http://kitt.hodsden.org/
 *
 * Original theme designed by DesignDisease, released By-SA through SmashingMagazine
 * http://designdisease.com/blog/compositio-wordpress-theme/
 * http://www.smashingmagazine.com/2009/02/18/compositio-clean-beautiful-and-free-wordpress-theme/
 */

/**
 * 
 */
function compositio_preprocess(&$vars) {

  // detect IE6
  $vars['browser'] = '';
  if (isset($_SERVER['HTTP_USER_AGENT']) && (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 6') !== false)) {
    $vars['browser'] = 'ie6';
  }
  return $vars;
}


/**
 * Adjust the node variables before passing to the node template file
 * @see theme_preprocess_node
 * @param array node variables array
 * @return array node variables array
 */
function compositio_preprocess_node(&$vars) {

	// adjust the links variable to fit the original design
	
	// comments
	if ($vars['comment'] > 0) {  // if comments allowed at all for this node
		$vars['comments'] = ($vars['comment_count'] > 0) ? 
			format_plural($vars['comment_count'], '1 comment', '@count comments') : t('No comments');
	}

	// tags
	$terms = '';
	foreach ($vars['taxonomy'] as $tid => $tinfo) {
		$terms .= empty($terms) ? '' : ', ';
		$terms .= l($tinfo['title'], $tinfo['href'], array('rel' => 'tag'));
	}
	if (!empty($terms)) { $vars['terms'] = $terms; }
}

/**
 * Adjust the comment variables before being passed to the comment template file
 * @see theme_preprocess_comment
 * @param array node variables array
 * @return array node variables array
 */
function compositio_preprocess_comment(&$vars) {

	// this is tragic.  Replace the ul and li for spans for layouts
	$l = $vars['links'];
	$l = preg_replace('|<ul class="links">|', '', preg_replace('|</ul>|', '', $l));
	$l = preg_replace('|<li\s+|', '<span ', preg_replace('|</li>|', '</span>&nbsp; ', $l));
	$vars['links'] = $l;
}

/**
 * Adjust the CSS classes and title before rendering the comment form section
 */
function compositio_comment_wrapper($content, $node) {
	if (!$content || $node->type == 'forum') {
		return '<div id="comments" class="comments-list">'. $content .'</div>';
	} else {
		$t = ($node->comment_count > 0) ? format_plural($node->comment_count, '1 Response', '@count Responses') : t('No Responses yet');
		$t .= ' to ';
		$t = t($t) . check_plain($node->title);
		return '<div id="comments" class="comments-list"><h2>'. $t .'</h2>'. $content .'</div>';
	}
}

function compositio_search_block_form($form) {
	
	$form['search_block_form_keys']['#title']="search";
	$form['search_block_form_keys']['#id']="searchterm";
	$form['search_block_form_keys']['#attributes'] = array(
		'class' => "formterm",
		'accesskey' => "3",
		);
	$form['submit']['#attributes']['class']="search-submit";
	$form['submit']['#value']="Search";

  /*
   * This is still a button, made an image via css, not HTML
   * @see <a href="http://drupal.org/node/51526" rel="nofollow">http://drupal.org/node/51526</a>
   */
}

